﻿#ifndef FRMMANAGER_H
#define FRMMANAGER_H

#include <QWidget>
#include "httplistener.h"
#include "httprequesthandler.h"
#include "HttpExt/requestmapper.h"

using namespace stefanfrings;

namespace Ui {
class FrmManager;
}

class FrmManager : public QWidget
{
    Q_OBJECT

public:
    explicit FrmManager(QWidget *parent = nullptr);
    ~FrmManager();

private:
    Ui::FrmManager *ui;

    enum MessageType{
        Connect = 0,
        Receive =1,
        Disconnect = 2
    };

    QSettings* listenerSettings;
    HttpListener *pHttpListener;

    bool HexReceiveTcpServer = false;    //16进制接收
    bool AsciiTcpServer = false;         //ASCII模式
    bool ShowConnectTcpServer = true;    //显示连接提示
    bool isOk =false;                    //是否监听

private slots:
    void initForm();
    void on_btnListen_clicked();
    void on_btnClear_clicked();
    void on_btnSave_clicked();
    void on_ckShowConnect_stateChanged(int arg1);
    void on_ckHexReceive_stateChanged(int arg1);
    //数据显示
    void append(MessageType type, const QString &data, bool clear = false);
    //HttP通讯相关
    void clientConnected(const QString &ip, int port);
    void clientDisconnected(const QString &ip, int port);
    void notify(const QString &ip, int port, const QString &data);
    void clientRequested(const QString &ip, int port, const QString &data);
    void serverListen(bool iblisten);

    //字符转换
    QByteArray encodeData(const QString& data, bool hex, bool ascii);
    QString decodeData(const QByteArray &data, bool hex, bool ascii);

    void on_ckAscii_stateChanged(int arg1);
};

#endif // FRMMANAGER_H
